package edu.chl.food_store.beans.ejb;

import edu.chl.food_store.entities.Product;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.*;

/**
 * ProductEJB:
 * Performs product operations on database. 
 */
@Stateless
public class ProductEJB {

    @PersistenceContext(unitName = "foodstore_pu")
    private EntityManager em;

    public List<Product> findProducts() {
        Query query = em.createNamedQuery("findAllProducts");
        return query.getResultList();
    }

    public void destroyProduct(Product product) {
        em.remove(em.find(Product.class, product.getId()));
    }

    public void createProduct(Product product) {
        em.persist(product);
    }
}
